<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户注册 - 家电维修系统</title>
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    <script th:src="@{/js/bootstrap.bundle.min.js}"></script>

    <style>
        body {
            background-color: #f8f9fa;
        }
        .register-container {
            max-width: 400px;
            margin: 100px auto;
            padding: 20px;
            background-color: white;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="register-container">
            <h2 class="text-center mb-4">用户注册</h2>
            <form id="registerForm">
                <div class="mb-3">
                    <label for="username" class="form-label">用户名</label>
                    <input type="text" class="form-control" id="username" name="username" required>
                </div>
                <div class="mb-3">
                    <label for="password" class="form-label">密码</label>
                    <input type="password" class="form-control" id="password" name="password" required>
                </div>
                <div class="mb-3">
                    <label for="realName" class="form-label">真实姓名</label>
                    <input type="text" class="form-control" id="realName" name="realName" required>
                </div>
                <div class="mb-3">
                    <label for="phone" class="form-label">手机号</label>
                    <input type="tel" class="form-control" id="phone" name="phone" required>
                </div>
                <div class="mb-3">
                    <label for="email" class="form-label">邮箱</label>
                    <input type="email" class="form-control" id="email" name="email" required>
                </div>
                <div class="mb-3">
                    <label for="address" class="form-label">地址</label>
                    <input type="text" class="form-control" id="address" name="address" required>
                </div>
                <div class="d-grid gap-2">
                    <button type="submit" class="btn btn-primary">注册</button>
                    <a href="/login" class="btn btn-link text-center">已有账号？立即登录</a>
                </div>
            </form>
        </div>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script>
        $(document).ready(function() {
            $('#registerForm').on('submit', function(e) {
                e.preventDefault();
                $.ajax({
                    url: '/api/auth/register',
                    type: 'POST',
                    contentType: 'application/json',
                    data: JSON.stringify({
                        username: $('#username').val(),
                        password: $('#password').val(),
                        realName: $('#realName').val(),
                        phone: $('#phone').val(),
                        email: $('#email').val(),
                        address: $('#address').val()
                    }),
                    success: function() {
                        alert('注册成功！');
                        window.location.href = '/login';
                    },
                    error: function(xhr) {
                        alert('注册失败：' + xhr.responseText);
                    }
                });
            });
        });
    </script>
</body>
</html> 